package ListNode;

import java.awt.image.AreaAveragingScaleFilter;
import java.util.Arrays;

public class Array {

    public int findIndex(int[] a,int m,int k) {
        for (int i = 0; i < m; i++) {
            if (a[i] <= k && a[i + 1] >= k) {
                return i;
            }
        }
        return -1;
    }
    public void insertNumToArray(int[] a,int m,int k){
        if(m<a.length){
            a[m]=k;
        }
       for(int i=0;i<=m;i++){
           for(int j=i+1;j<=m;j++){
               if(a[i]>a[j]){
                   int temp=a[i];
                   a[i]=a[j];
                   a[j]=temp;
               }
           }
       }
    }

    public void merge(int[] a,int m,int[] b,int n){
        int i=m-1;
        int j=n-1;
        int index=m+n-1;
        while(i>=0&&j>=0)
            a[index--]=a[i]>b[j]?a[i--]:b[j--];
        while(j>=0)
            a[index--]=b[j--];
    }

    public ListNode getKNode(ListNode head,int k){
        ListNode node=head;
        int count=0;
        while(node!=null)
            count++;
        if(k>count)
            return null;
        int res=count-k+1;
        int counter=0;
        while(counter!=res)
        {
            counter++;
            if(counter==k)
                return head;

        }
        return null;
    }
    public static void main(String[] args){
        int a[]=new int[10];
        a[0]=1;
        a[1]=2;
        a[2]=3;
        a[3]=4;
        int b[]=new int[10];
        b[0]=1;
        b[1]=1;
        b[2]=3;
        Array array=new Array();
        array.merge(a,4,b,3);
        for(int i=0;i<a.length;i++){
            System.out.print(a[i]+" ");
        }
    }
}
